package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @author vivi
 * @description
 * @date 2024/5/24
 */
@RestController  // == @Controller + @ResponseBody
//                                    返回的是数据， 让不是页面， 默认是页面
// 指定配置文件
@PropertySource(value = "application.yml", encoding = "utf8")
public class TestController {
//    @Value("mytest") // !error: 把 括号内的字符串 赋值给了 变量mytest
    @Value("${mytest}")
    private String mytest;

    @Value("${mytest2}")
    private String mytest2;

    @Autowired
    private Student student;

//    @PostConstruct
//    public void postConstruct() {
//        System.out.println(student);
//    }

    @Autowired
    private ListDemo listDemo;

    @PostConstruct
    public void postConstruct() {
        System.out.println(listDemo);
    }


    @RequestMapping("/hello") // url 路由注册
    public String show(String name) {
        if (! StringUtils.hasLength(name)) {
            name = "sehun";
        }
        return name + " hello!";
    }

    @RequestMapping("/getMytest")
    public String getMytest () {
        return mytest + " " + mytest2;
    }

}

















